package common

import (
	"io/ioutil"
	"log"
	"net/http"
	"time"
)

/**
 * @ param url：请求地址
 * @ return int 请求码 byte请求结果
 */
func GetRequest(url string) (requestCode int, resultByte []byte) {
	// 构建http连接对象
	client := &http.Client{Timeout: 5 * time.Second}
	res, err := client.Get(url)
	if err != nil {
		log.Println("网络请求异常：" + err.Error())
		return http.StatusInternalServerError, nil
	}
	defer res.Body.Close()
	all, readErr := ioutil.ReadAll(res.Body)
	if readErr != nil {
		log.Println("网络请求读取异常：" + readErr.Error())
		return http.StatusInternalServerError, nil
	}
	return res.StatusCode, all
}
